boomBoomCowboy.stateManager = (function() {
	var manager = StateMachine.create({
		events : [
			// { name : 'load', from : 'none', to : 'loading' },
			{ name : 'startup', from : 'none', to : 'menu' },
			{ name : 'start', from : 'menu', to : 'game' },
			{ name : 'showHelp', from : 'menu', to : 'help'},
			{ name : 'showCredits', from : 'menu', to : 'credits' },
			{ name : 'exit', from : 'game', to : 'menu' },
			{ name : 'pause', from : 'game', to :'paused' },
			{ name : 'unpause', from : 'paused', to : 'game' },
			{ name : 'win', from : 'game', to : 'gameWon' },
			{ name : 'returnToMenu', from : ['help', 'credits'], to : 'menu' }
		]
	});

	// Load transition
	manager.onbeforeload = function() {
		
	}
	
	// Startup transition
	manager.onbeforestartup = function() {
		$("#gamescreen").hide();
		$("#mainscreen").show();
		$("#menuscreen").show();
		$("#helpscreen").hide();
		$("#creditscreen").hide();
		$("#returnToMenu").hide();
	}
	
	// Start transition
	manager.onbeforestart = function() {
		$("#mainscreen").hide();
		$("#gamescreen").show();
		boomBoomCowboy.game.init();
	}
	
	// Exit transition
	manager.onbeforeexit = function() {
		
	}
	
	// Pause transition
	manager.onbeforepause = function() {
		
	}
	
	// Unpause transition
	manager.onbeforeunpause = function() {
		
	}
	
	// Win transition
	manager.onbeforewin = function() {
		
	}
	
	// Help transition
	manager.onbeforeshowHelp = function() {
		$("#menuscreen").hide();
		$("#helpscreen").fadeToggle();
		$("#returnToMenu").fadeToggle();
	}
	
	// Credit transition
	manager.onbeforeshowCredits = function() {
		$("#menuscreen").hide();
		$("#creditscreen").fadeToggle();
		$("#returnToMenu").fadeToggle();
	}
	
	// Return transition
	manager.onbeforereturnToMenu = function() {
		if($("#helpscreen").is(":visible"))
			$("#helpscreen").hide();
		else
			$("#creditscreen").hide();
		$("#returnToMenu").hide();
			
		$("#menuscreen").fadeToggle();
	}	
	
	
	return {
		instance : manager
	}
})(); 